package com.example.device.vm

import androidx.lifecycle.viewModelScope
import com.example.common.view.vm.BaseViewModel
import com.example.device.api.DeviceApiService
import com.example.device.entity.PollingEntity
import com.example.device.model.DeviceRepository
import com.example.device.model.DeviceResultData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class PollingEditViewModel @Inject constructor(private val apiService: DeviceApiService):BaseViewModel<DeviceRepository,DeviceResultData<PollingEntity>>(){
    fun postPolling(pollingEntity: PollingEntity){
        viewModelScope.launch (mDispatcher){
            try {
                val result = apiService.postPolling(pollingEntity)
                mSuccessLiveData.postValue(result)
            } catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}